**REStat, "Breastfeeding and Children's Early Cognitive Outcomes".  Program whether married at child's date of birth;

libname dd 'D:\local_c\bfeed3';

data x;
infile 'D:\local_c\bfeed3\mar08.dat' lrecl=1045 missover DSD DLM=' ';
input
  R0000100
  R0172500
  R0214700
  R0214800
  R0217501
  R0329200
  R0405601
  R0530700
  R0618601
  R0809900
  R0898401
  R1045700
  R1144901
  R1427500
  R1520101
  R1794600
  R1890801
  R2156200
  R2257901
  R2259845
  R2259846
  R2259847
  R2259848
  R2259849
  R2259850
  R2259851
  R2259852
  R2259853
  R2259854
  R2365700
  R2445301
  R2448045
  R2448046
  R2448047
  R2448048
  R2448049
  R2448050
  R2448051
  R2448052
  R2448053
  R2448054
  R2742500
  R2871000
  R2878400
  R2878500
  R2878600
  R2878700
  R2878800
  R2878900
  R2879000
  R2879100
  R2879200
  R2879300
  R2986100
  R3074700
  R3076850
  R3076851
  R3076852
  R3076853
  R3076854
  R3076855
  R3076856
  R3076857
  R3076858
  R3076859
  R3302500
  R3401400
  R3408500
  R3408600
  R3408700
  R3408800
  R3408900
  R3409000
  R3409100
  R3409200
  R3409300
  R3409400
  R3573400
  R3656800
  R3659055
  R3659056
  R3659057
  R3659058
  R3659059
  R3659060
  R3659061
  R3659062
  R3659063
  R3659064
  R3917600
  R4007300
  R4009455
  R4009456
  R4009457
  R4009458
  R4009459
  R4009460
  R4009461
  R4009462
  R4009463
  R4009464
  R4100200
  R4100202
  R4418400
  R4445900
  R4446000
  R4446100
  R4446200
  R4446300
  R4446400
  R4446500
  R4446600
  R4446700
  R4446701
  R4500201
  R4500202
  R5081400
  R5088700
  R5088800
  R5088900
  R5089000
  R5089100
  R5089200
  R5089300
  R5089400
  R5089500
  R5089600
  R5166700
  R5174500
  R5174600
  R5174700
  R5174800
  R5174900
  R5175000
  R5175100
  R5175200
  R5175300
  R5175400
  R5200201
  R5200202
  R6435301
  R6435302
  R6479300
  R6487600
  R6487700
  R6487800
  R6487900
  R6488000
  R6488100
  R6488200
  R6488300
  R6488400
  R6488500
  R6963301
  R6963302
  R7007000
  R7015400
  R7015500
  R7015600
  R7015700
  R7015800
  R7015900
  R7016000
  R7016100
  R7016200
  R7016300
  R7656301
  R7656302
  R7704300
  R7713000
  R7713100
  R7713200
  R7713300
  R7713400
  R7713500
  R7713600
  R7713700
  R7713800
  R7713900
  R8423201
  R8423202
  R8496700
  R8505700
  R8505800
  R8505900
  R8506000
  R8506100
  R8506200
  R8506300
  R8506400
  R8506500
  R8506600
  R9908700
  R9908800
  R9908900
  R9909000
  R9909100
  R9909200
  R9909300
  R9909400
  R9909500
  R9909600
  T0967301
  T0967302
  T0988500
  T0997400
  T0997500
  T0997600
  T0997700
  T0997800
  T0997900
  T0998000
  T0998100
  T0998200
  T0998300
  T2190501
  T2190502
  T2210500
  T2219200
  T2219300
  T2219400
  T2219500
  T2219600
  T2219700
  T2219800
  T2219900
  T2220000
  T2220100
;

  label R0000100 = "ID# (1-12686) 79";
  label R0172500 = "INT REM INT DATE - MONTH 79";
  label R0214700 = "RACL/ETHNIC COHORT /SCRNR 79";
  label R0214800 = "SEX OF R 79";
  label R0217501 = "MARITAL STATUS 79";
  label R0329200 = "INT REM INT DATE - MONTH 80";
  label R0405601 = "MARITAL STATUS 80";
  label R0530700 = "INT REM INT DATE - MONTH 81";
  label R0618601 = "MARITAL STATUS 81";
  label R0809900 = "INT REM INT DATE - MONTH 82";
  label R0898401 = "MARITAL STATUS 82";
  label R1045700 = "INT REM INT DATE - MONTH 83";
  label R1144901 = "MARITAL STATUS 83";
  label R1427500 = "INT REM INT DATE - MONTH 84";
  label R1520101 = "MARITAL STATUS 84";
  label R1794600 = "INT REM INT DATE - MONTH 85";
  label R1890801 = "MARITAL STATUS 85";
  label R2156200 = "INT REM INT DATE - MONTH 86";
  label R2257901 = "MARITAL STATUS 86";
  label R2259845 = "MONTH BGN MARRIAGE#1 SIN 86";
  label R2259846 = "YR BGN 1ST MARRIAGE 86";
  label R2259847 = "MONTH ENDED 1ST MARRIAGE 86";
  label R2259848 = "YR END 1ST MARRIAGE 86";
  label R2259849 = "MONTH BGN MARRIAGE#2 SIN 86";
  label R2259850 = "YR BGN 2ND MARRIAGE 86";
  label R2259851 = "MONTH ENDED 2ND MARRIAGE 86";
  label R2259852 = "YR END 2ND MARRIAGE 86";
  label R2259853 = "MONTH BGN MARRIAGE#3 SIN 86";
  label R2259854 = "YR BGN 3RD MARRIAGE 86";
  label R2365700 = "INT REM INT DATE - MONTH 87";
  label R2445301 = "MARITAL STATUS 87";
  label R2448045 = "MONTH BGN MARRIAGE#1 SIN 87";
  label R2448046 = "YR BGN 1ST MARRIAGE 87";
  label R2448047 = "MONTH ENDED 1ST MARRIAGE 87";
  label R2448048 = "YR END 1ST MARRIAGE 87";
  label R2448049 = "MONTH BGN MARRIAGE#2 SIN 87";
  label R2448050 = "YR BGN 2ND MARRIAGE 87";
  label R2448051 = "MONTH ENDED 2ND MARRIAGE 87";
  label R2448052 = "YR END 2ND MARRIAGE 87";
  label R2448053 = "MONTH BGN MARRIAGE#3 SIN 87";
  label R2448054 = "YR BGN 3RD MARRIAGE 87";
  label R2742500 = "INT REM INT DATE - MONTH 88";
  label R2871000 = "MARITAL STATUS 88";
  label R2878400 = "MONTH BGN MARRIAGE#1 SIN 88";
  label R2878500 = "YR BGN 1ST MARRIAGE 88";
  label R2878600 = "MONTH ENDED 1ST MARRIAGE 88";
  label R2878700 = "YR END 1ST MARRIAGE 88";
  label R2878800 = "MONTH BGN MARRIAGE#2 SIN 88";
  label R2878900 = "YR BGN 2ND MARRIAGE 88";
  label R2879000 = "MONTH ENDED 2ND MARRIAGE 88";
  label R2879100 = "YR END 2ND MARRIAGE 88";
  label R2879200 = "MONTH BGN MARRIAGE#3 SIN 88";
  label R2879300 = "YR BGN 3RD MARRIAGE 88";
  label R2986100 = "INT REM INT DATE - MONTH 89";
  label R3074700 = "MARITAL STATUS 89";
  label R3076850 = "MONTH BGN MARRIAGE#1 SIN 89";
  label R3076851 = "YR BGN 1ST MARRIAGE 89";
  label R3076852 = "MONTH ENDED 1ST MARRIAGE 89";
  label R3076853 = "YR END 1ST MARRIAGE 89";
  label R3076854 = "MONTH BGN MARRIAGE#2 SIN 89";
  label R3076855 = "YR BGN 2ND MARRIAGE 89";
  label R3076856 = "MONTH ENDED 2ND MARRIAGE 89";
  label R3076857 = "YR END 2ND MARRIAGE 89";
  label R3076858 = "MONTH BGN MARRIAGE#3 SIN 89";
  label R3076859 = "YR BGN 3RD MARRIAGE 89";
  label R3302500 = "INT REM INT DATE - MONTH 90";
  label R3401400 = "MARITAL STATUS 90";
  label R3408500 = "MONTH BGN MARRIAGE#1 SIN 90";
  label R3408600 = "YR BGN 1ST MARRIAGE 90";
  label R3408700 = "MONTH ENDED 1ST MARRIAGE 90";
  label R3408800 = "YR END 1ST MARRIAGE 90";
  label R3408900 = "MONTH BGN MARRIAGE#2 SIN 90";
  label R3409000 = "YR BGN 2ND MARRIAGE 90";
  label R3409100 = "MONTH ENDED 2ND MARRIAGE 90";
  label R3409200 = "YR END 2ND MARRIAGE 90";
  label R3409300 = "MONTH BGN MARRIAGE#3 SIN 90";
  label R3409400 = "YR BGN 3RD MARRIAGE 90";
  label R3573400 = "INT REM INT DATE - MONTH 91";
  label R3656800 = "MARITAL STATUS 91";
  label R3659055 = "MONTH BGN MARRIAGE#1 SIN 91";
  label R3659056 = "YR BGN 1ST MARRIAGE 91";
  label R3659057 = "MONTH ENDED 1ST MARRIAGE 91";
  label R3659058 = "YR END 1ST MARRIAGE 91";
  label R3659059 = "MONTH BGN MARRIAGE#2 SIN 91";
  label R3659060 = "YR BGN 2ND MARRIAGE 91";
  label R3659061 = "MONTH ENDED 2ND MARRIAGE 91";
  label R3659062 = "YR END 2ND MARRIAGE 91";
  label R3659063 = "MONTH BGN MARRIAGE#3 SIN 91";
  label R3659064 = "YR BGN 3RD MARRIAGE 91";
  label R3917600 = "INT REM INT DATE - MONTH 92";
  label R4007300 = "MARITAL STATUS 92";
  label R4009455 = "MONTH BGN MARRIAGE#1 SIN 92";
  label R4009456 = "YR BGN 1ST MARRIAGE 92";
  label R4009457 = "MONTH ENDED 1ST MARRIAGE 92";
  label R4009458 = "YR END 1ST MARRIAGE 92";
  label R4009459 = "MONTH BGN MARRIAGE#2 SIN 92";
  label R4009460 = "YR BGN 2ND MARRIAGE 92";
  label R4009461 = "MONTH ENDED 2ND MARRIAGE 92";
  label R4009462 = "YR END 2ND MARRIAGE 92";
  label R4009463 = "MONTH BGN MARRIAGE#3 SIN 92";
  label R4009464 = "YR BGN 3RD MARRIAGE 92";
  label R4100200 = "DATE OF INTERVIEW 93:MO";
  label R4100202 = "DATE OF INTERVIEW 93:YR";
  label R4418400 = "MARITAL STATUS 93";
  label R4445900 = "MONTH BGN MARRIAGE#1  93";
  label R4446000 = "YR BGN 1ST MARRIAGE 93";
  label R4446100 = "MONTH ENDED 1ST MARRIAGE 93";
  label R4446200 = "YR END 1ST MARRIAGE 93";
  label R4446300 = "MONTH BGN MARRIAGE#2  93";
  label R4446400 = "YR BGN 2ND MARRIAGE 93";
  label R4446500 = "MONTH ENDED 2ND MARRIAGE 93";
  label R4446600 = "YR END 2ND MARRIAGE 93";
  label R4446700 = "MONTH BGN MARRIAGE#3  93";
  label R4446701 = "YR BGN 3RD MARRIAGE 93";
  label R4500201 = "DATE OF INTERVIEW 94";
  label R4500202 = "DATE OF INTERVIEW 94";
  label R5081400 = "MARITAL STATUS 94";
  label R5088700 = "MONTH BEGAN 1ST MARRIAGE AS OF 94 INT";
  label R5088800 = "YEAR BEGAN 1ST MARRIAGE AS OF 94 INT";
  label R5088900 = "MONTH ENDED 1ST MARRIAGE AS OF 94 INT";
  label R5089000 = "YEAR ENDED 1ST MARRIAGE AS OF 94 INT";
  label R5089100 = "MONTH BEGAN 2ND MARRIAGE AS OF 94 INT";
  label R5089200 = "YEAR BEGAN 2ND MARRIAGE AS OF 94 INT";
  label R5089300 = "MONTH ENDED 2ND MARRIAGE AS OF 94 INT";
  label R5089400 = "YEAR ENDED 2ND MARRIAGE AS OF 94 INT";
  label R5089500 = "MONTH BEGAN 3RD MARRIAGE AS OF 94 INT";
  label R5089600 = "YEAR BEGAN 3RD MARRIAGE AS OF 94 INT";
  label R5166700 = "MARITAL STATUS 96";
  label R5174500 = "MONTH BEGAN 1ST MARRIAGE AS OF 96 INT";
  label R5174600 = "YEAR BEGAN 1ST MARRIAGE AS OF 96 INT";
  label R5174700 = "MONTH ENDED 1ST MARRIAGE AS OF 96 INT";
  label R5174800 = "YEAR ENDED 1ST MARRIAGE AS OF 96 INT";
  label R5174900 = "MONTH BEGAN 2ND MARRIAGE AS OF 96 INT";
  label R5175000 = "YEAR BEGAN 2ND MARRIAGE AS OF 96 INT";
  label R5175100 = "MONTH ENDED 2ND MARRIAGE AS OF 96 INT";
  label R5175200 = "YEAR ENDED 2ND MARRIAGE AS OF 96 INT";
  label R5175300 = "MONTH BEGAN 3RD MARRIAGE AS OF 96 INT";
  label R5175400 = "YEAR BEGAN 3RD MARRIAGE AS OF 96 INT";
  label R5200201 = "DATE OF INTERVIEW 96";
  label R5200202 = "DATE OF INTERVIEW 96";
  label R6435301 = "DATE OF INTERVIEW 1998";
  label R6435302 = "DATE OF INTERVIEW 1998";
  label R6479300 = "MARITAL STATUS 1998";
  label R6487600 = "MONTH BEGAN 1ST MARRG AS OF 98 INT 1998";
  label R6487700 = "YEAR BEGAN 1ST MARRG AS OF 98 INT 1998";
  label R6487800 = "MONTH ENDED 1ST MARRG AS OF 98 INT 1998";
  label R6487900 = "YEAR ENDED 1ST MARRG AS OF 98 INT 1998";
  label R6488000 = "MON BEGAN 2ND MARRIAGE AS OF 98 INT 1998";
  label R6488100 = "YEAR BEGAN 2ND MARRG AS OF 98 INT 1998";
  label R6488200 = "MONTH ENDED 2ND MARRG AS OF 98 INT 1998";
  label R6488300 = "YEAR ENDED 2ND MARRG AS OF 98 INT 1998";
  label R6488400 = "MONTH BEGAN 3RD MARRG AS OF 98 INT 1998";
  label R6488500 = "YEAR BEGAN 3RD MARRG AS OF 98 INT 1998";
  label R6963301 = "DATE OF INTERVIEW 2000";
  label R6963302 = "DATE OF INTERVIEW 2000";
  label R7007000 = "MARITAL STATUS 2000";
  label R7015400 = "MONTH BEGAN 1ST MARRG AS OF 00 INT 2000";
  label R7015500 = "YEAR BEGAN 1ST MARRG AS OF 00 INT 2000";
  label R7015600 = "MONTH ENDED 1ST MARRG AS OF 00 INT 2000";
  label R7015700 = "YEAR ENDED 1ST MARRG AS OF 00 INT 2000";
  label R7015800 = "MON BEGAN 2ND MARRIAGE AS OF 00 INT 2000";
  label R7015900 = "YEAR BEGAN 2ND MARRG AS OF 00 INT 2000";
  label R7016000 = "MONTH ENDED 2ND MARRG AS OF 00 INT 2000";
  label R7016100 = "YEAR ENDED 2ND MARRG AS OF 00 INT 2000";
  label R7016200 = "MONTH BEGAN 3RD MARRG AS OF 00 INT 2000";
  label R7016300 = "YEAR BEGAN 3RD MARRG AS OF 00 INT 2000";
  label R7656301 = "DATE OF INTERVIEW 2002";
  label R7656302 = "DATE OF INTERVIEW 2002";
  label R7704300 = "MARITAL STATUS 2002";
  label R7713000 = "MONTH BEGAN 1ST MARRG AS OF 02 INT 2002";
  label R7713100 = "YEAR BEGAN 1ST MARRG AS OF 02 INT 2002";
  label R7713200 = "MONTH ENDED 1ST MARRG AS OF 02 INT 2002";
  label R7713300 = "YEAR ENDED 1ST MARRG AS OF 02 INT 2002";
  label R7713400 = "MON BEGAN 2ND MARRIAGE AS OF 02 INT 2002";
  label R7713500 = "YEAR BEGAN 2ND MARRG AS OF 02 INT 2002";
  label R7713600 = "MONTH ENDED 2ND MARRG AS OF 02 INT 2002";
  label R7713700 = "YEAR ENDED 2ND MARRG AS OF 02 INT 2002";
  label R7713800 = "MONTH BEGAN 3RD MARRG AS OF 02 INT 2002";
  label R7713900 = "YEAR BEGAN 3RD MARRG AS OF 02 INT 2002";
  label R8423201 = "DATE OF INTERVIEW 2004";
  label R8423202 = "DATE OF INTERVIEW 2004";
  label R8496700 = "MARITAL STATUS 2004";
  label R8505700 = "MONTH BEGAN 1ST MARRG AS OF 04 INT 2004";
  label R8505800 = "YEAR BEGAN 1ST MARRG AS OF 04 INT 2004";
  label R8505900 = "MONTH ENDED 1ST MARRG AS OF 04 INT 2004";
  label R8506000 = "YEAR ENDED 1ST MARRG AS OF 04 INT 2004";
  label R8506100 = "MON BEGAN 2ND MARRIAGE AS OF 04 INT 2004";
  label R8506200 = "YEAR BEGAN 2ND MARRG AS OF 04 INT 2004";
  label R8506300 = "MONTH ENDED 2ND MARRG AS OF 04 INT 2004";
  label R8506400 = "YEAR ENDED 2ND MARRG AS OF 04 INT 2004";
  label R8506500 = "MONTH BEGAN 3RD MARRG AS OF 04 INT 2004";
  label R8506600 = "YEAR BEGAN 3RD MARRG AS OF 04 INT 2004";
  label R9908700 = "MONTH BEGAN 1ST MARRG XRND";
  label R9908800 = "YEAR BEGAN 1ST MARRG XRND";
  label R9908900 = "MONTH ENDED 1ST MARRG XRND";
  label R9909000 = "YEAR ENDED 1ST MARRG XRND";
  label R9909100 = "MON BEGAN 2ND MARRIAGE XRND";
  label R9909200 = "YEAR BEGAN 2ND MARRG XRND";
  label R9909300 = "MONTH ENDED 2ND MARRG XRND";
  label R9909400 = "YEAR ENDED 2ND MARRG XRND";
  label R9909500 = "MONTH BEGAN 3RD MARRG XRND";
  label R9909600 = "YEAR BEGAN 3RD MARRG XRND";
  label T0967301 = "DATE OF INTERVIEW 2006";
  label T0967302 = "DATE OF INTERVIEW 2006";
  label T0988500 = "MARITAL STATUS 2006";
  label T0997400 = "MONTH BEGAN 1ST MARRG AS OF 06 INT 2006";
  label T0997500 = "YEAR BEGAN 1ST MARRG AS OF 06 INT 2006";
  label T0997600 = "MONTH ENDED 1ST MARRG AS OF 06 INT 2006";
  label T0997700 = "YEAR ENDED 1ST MARRG AS OF 06 INT 2006";
  label T0997800 = "MON BEGAN 2ND MARRIAGE AS OF 06 INT 2006";
  label T0997900 = "YEAR BEGAN 2ND MARRG AS OF 06 INT 2006";
  label T0998000 = "MONTH ENDED 2ND MARRG AS OF 06 INT 2006";
  label T0998100 = "YEAR ENDED 2ND MARRG AS OF 06 INT 2006";
  label T0998200 = "MONTH BEGAN 3RD MARRG AS OF 06 INT 2006";
  label T0998300 = "YEAR BEGAN 3RD MARRG AS OF 06 INT 2006";
  label T2190501 = "DATE OF INTERVIEW 2008";
  label T2190502 = "DATE OF INTERVIEW 2008";
  label T2210500 = "MARITAL STATUS 2008";
  label T2219200 = "MONTH BEGAN 1ST MARRG AS OF 08 INT 2008";
  label T2219300 = "YEAR BEGAN 1ST MARRG AS OF 08 INT 2008";
  label T2219400 = "MONTH ENDED 1ST MARRG AS OF 08 INT 2008";
  label T2219500 = "YEAR ENDED 1ST MARRG AS OF 08 INT 2008";
  label T2219600 = "MON BEGAN 2ND MARRIAGE AS OF 08 INT 2008";
  label T2219700 = "YEAR BEGAN 2ND MARRG AS OF 08 INT 2008";
  label T2219800 = "MONTH ENDED 2ND MARRG AS OF 08 INT 2008";
  label T2219900 = "YEAR ENDED 2ND MARRG AS OF 08 INT 2008";
  label T2220000 = "MONTH BEGAN 3RD MARRG AS OF 08 INT 2008";
  label T2220100 = "YEAR BEGAN 3RD MARRG AS OF 08 INT 2008";

data y;
set dd.child08;
keep c0000100 c0000200 r0000100 cmob cyob bfeed math56;

r0000100 = c0000200;

proc sort;  by r0000100;

data z;
merge x y;  by r0000100;

if cyob ne .;

data dd.marst08;
set z;

*let's first form the child's birth date;
bd = (cyob-1950)*12 + cmob;

**okay, it turns out I can just use the xround variable;
firsmo = r9908700;
firsyr = r9908800;
firpmo = r9908900;
firpyr = r9909000;
secsmo = r9909100;
secsyr = r9909200;
secpmo = r9909300;
secpyr = r9909400;
thismo = r9909500;
thisyr = r9909600;

mars1 = .;
marp1 = .;
mars2 = .;
marp2 = .;
mars3 = .;
if (firsyr gt 1970 and firsmo gt 0) then do;
mars1 = (firsyr-1950)*12 + firsmo;
end;
if (firpyr gt 1970 and firpmo gt 0) then do;
marp1 = (firpyr-1950)*12 + firpmo;
end;
if (secsyr gt 1970 and secsmo gt 0) then do;
mars2 = (secsyr-1950)*12 + secsmo;
end;
if (secpyr gt 1970 and secpmo gt 0) then do;
marp2 = (secpyr-1950)*12 + secpmo;
end;
if (thisyr gt 1970 and thismo gt 0) then do;
mars3 = (thisyr-1950)*12 + thismo;
end;

**okay, let's code it up;
**married at child's birth;
marbirth = .;
**first marriage timing;
if (mars1 gt 0) then do;
   if bd lt mars1 then marbirth = 0;
end;
if (mars1 gt 0 and marp1 gt 0) then do;
    if (bd ge mars1 and bd le marp1) then marbirth = 1;
end;
if (mars1 gt 0 and firpyr = -998) then do;
    if (bd ge mars1) then marbirth = 1;
end;
**second marriage timing;
if (marp1 gt 0 and mars2 gt 0) then do;
   if (bd gt marp1 and bd lt mars2) then marbirth = 0;
end;
if (mars2 gt 0 and marp2 gt 0) then do;
    if (bd ge mars2 and bd le marp2) then marbirth = 1;
end;
if (mars2 gt 0 and secpyr = -996) then do;
    if (bd ge mars2) then marbirth = 1;
end;
**third marriage timing;
if (marp2 gt 0 and mars3 gt 0) then do;
   if (bd gt marp2 and bd lt mars3) then marbirth = 0;
end;
if (marp2 gt 0 and bd gt marp2 and thisyr = -995) then marbirth = 0;


if firsmo = -999 then marbirth = 0;

**hand coded;
if (c0000100 = 207704 or c0000100 = 624502 or c0000100 = 866402
    or c0000100 = 464103 or c0000100 = 533803 or c0000100 = 797103
    or c0000100 = 943401 or c0000100 = 1037304 or c0000100 = 76404
    or c0000100 = 861402 or c0000100 = 50402 or c0000100 = 588803
    or c0000100 = 943402 or c0000100 = 20302 or c0000100 = 325301
    or c0000100 = 666802 or c0000100 = 761903 or c0000100 = 793303
    or c0000100 = 109003 or c0000100 = 291103 or c0000100 = 715804
    or c0000100 = 137502 or c0000100 = 199303 or c0000100 = 200207
    or c0000100 = 268102 or c0000100 = 277802 or c0000100 = 700004
    or c0000100 = 738302 or c0000100 = 745903 or c0000100 = 755101
    or c0000100 = 839104 or c0000100 = 853903 or c0000100 = 861504
    or c0000100 = 885302 or c0000100 = 995302 or c0000100 = 1053502
    or c0000100 = 47501 or c0000100 = 75903 or c0000100 = 121202
    or c0000100 = 354803 or c0000100 = 578003 or c0000100 = 589703
    or c0000100 = 629503 or c0000100 = 688002 or c0000100 = 926002
    or c0000100 = 1012502 or c0000100 = 1045202 or c0000100 = 452801
    or c0000100 = 62103 or c0000100 = 200208 or c0000100 = 277803
    or c0000100 = 317802 or c0000100 = 344603 or c0000100 = 597305
    or c0000100 = 597306 or c0000100 = 606301 or c0000100 = 1016202
    or c0000100 = 50403 or c0000100 = 75904 or c0000100 = 597307
    or c0000100 = 731402 or c0000100 = 782201 or c0000100 = 860103
    or c0000100 = 992202 or c0000100 = 995303 or c0000100 = 1188201
    or c0000100 = 1219302 or c0000100 = 182904 or c0000100 = 363303
    or c0000100 = 372904 or c0000100 = 372905 or c0000100 = 603901
    or c0000100 = 745904 or c0000100 = 1002403 or c0000100 = 1033203
    or c0000100 = 514201 or c0000100 = 620503 or c0000100 = 691501
    or c0000100 = 744303 or c0000100 = 840502 or c0000100 = 995104
    or c0000100 = 731403 or c0000100 = 782803 or c0000100 = 758502
    or c0000100 = 769504 or c0000100 = 968602 or c0000100 = 1033205
    or c0000100 = 759502 or c0000100 = 764902 or c0000100 = 892003
    or c0000100 = 995304 or c0000100 = 1033204 or c0000100 = 1208303
    or c0000100 = 185304 or c0000100 = 200210 or c0000100 = 447304
    or c0000100 = 509002 or c0000100 = 520101 or c0000100 = 531704
    or c0000100 = 840501 or c0000100 = 678804 or c0000100 = 200209
    or c0000100 = 456102 or c0000100 = 5317103 or c0000100 = 715805
    or c0000100 = 755301 or c0000100 = 809302 or c0000100 = 834305
    or c0000100 = 848003 or c0000100 = 992702 or c0000100 = 449602
    or c0000100 = 600302 or c0000100 = 252802 or c0000100 = 80102
    or c0000100 = 446303 or c0000100 = 850301 or c0000100 = 724601
    or c0000100 = 887002 or c0000100 = 1037303 or c0000100 = 588802
    or c0000100 = 996703 or c0000100 = 84101 or c0000100 = 1037302
    or c0000100 = 108601 or c0000100 = 271003 or c0000100 = 415303
    or c0000100 = 531703 or c0000100 = 728504 or c0000100 = 756001
    or c0000100 = 1178601
    or c0000100 = 70605 or c0000100 = 106902 or c0000100 = 240401 or 
       c0000100 = 517602 or c0000100 = 632205) then marbirth = 0;

if (c0000100 = 500901 or c0000100 = 1037802 or c0000100 = 276903
   or c0000100 = 976601 or c0000100 = 347602 or c0000100 = 83603
   or c0000100 = 347603 or c0000100 = 797105 or c0000100 = 892002
   or c0000100 = 516302 or c0000100 = 588804 or c0000100 = 225201
   or c0000100 = 347604 or c0000100 = 671801 or c0000100 = 461301
   or c0000100 = 449401 or c0000100 = 124102 or c0000100 = 817403
   or c0000100 = 463802 or c0000100 = 344703 or c0000100 = 588801
   or c0000100 = 667602 or c0000100 = 861401 or c0000100 = 594802
   or c0000100 = 715803 or c0000100 = 264002 or c0000100 = 594801
   or c0000100 = 665401 or c0000100 = 667601 or c0000100 = 934902
   or c0000100 = 250501 or c0000100 = 288603 or c0000100 = 344702
   or c0000100 = 626301 or c0000100 = 715801 or c0000100 = 715802
   or c0000100 = 817402 or c0000100 = 66805 or c0000100 = 914801 or
   c0000100 = 75202 or c0000100 = 426204 or c0000100 = 484901 or c0000100 = 970702)
   then marbirth = 1;

**hand code some more;
   if (c0000100 = 1901 or c0000100 = 217901 or c0000100 = 217902 or c0000100 = 217903
     or c0000100 = 291102 or c0000100 = 354302 or c0000100 = 354303
     or c0000100 = 554705 or c0000100 = 746402 or c0000100 = 982801
     or c0000100 = 982802 or c0000100 = 982803 or c0000100 = 982805
     or c0000100 = 991601 or c0000100 = 991603 or c0000100 = 1010601
     or c0000100 = 1021101 or c0000100 = 1021103 or c0000100 = 1053301
     or c0000100 = 1191801 or c0000100 = 1191803 or c0000100 = 304801
     or c0000100 = 230801 or c0000100 = 1075201 or c0000100 = 597301 
     or c0000100 = 967103 or c0000100 = 47101 or c0000100 = 630704
     or c0000100 = 19001 or c0000100 = 143901 or c0000100 = 437201
     or c0000100 = 516301 or c0000100 = 700003 or c0000100 = 792802
     or c0000100 = 792803 or c0000100 = 1037803 or c0000100 = 484902
     or c0000100 = 814101 or c0000100 = 814102 or c0000100 = 980702 or c0000100 = 54602
     or c0000100 = 737502 or c0000100 = 192802 or c0000100 = 192803 or c0000100 = 347601
     or c0000100 = 797102 or c0000100 = 797104 or c0000100 = 231503 or c0000100 = 1250502
     or c0000100 = 125901 or c0000100 = 132801 or c0000100 = 580602 or c0000100 = 622703
     or c0000100 = 768104 or c0000100 = 800105 or c0000100 = 834303 or c0000100 = 47402
     or c0000100 = 132802 or c0000100 = 256903 or c0000100 = 493003 or c0000100 = 817407
     or c0000100 = 130501 or c0000100 = 149402 or c0000100 = 149403 or c0000100 = 444502
     or c0000100 = 506402 or c0000100 = 506403 or c0000100 = 531102 or c0000100 = 531103
     or c0000100 = 532802 or c0000100 = 1011702 or c0000100 = 1018304 or c0000100 = 1213702
     or c0000100 = 1213703 or c0000100 = 25602 or c0000100 = 42504 or c0000100 = 80501
     or c0000100 = 124104 or c0000100 = 153203 or c0000100 = 153204 or c0000100 = 159202
     or c0000100 = 173001 or c0000100 = 175405 or c0000100 = 175406 or c0000100 = 213003
     or c0000100 = 215304 or c0000100 = 221503 or c0000100 = 221504 or c0000100 = 239803
     or c0000100 = 280802 or c0000100 = 280803 or c0000100 = 409901 or c0000100 = 423204
     or c0000100 = 436703 or c0000100 = 444503 or c0000100 = 446503 or c0000100 = 522501
     or c0000100 = 532803 or c0000100 = 538703 or c0000100 = 538704 or c0000100 = 538705
     or c0000100 = 547402 or c0000100 = 554601 or c0000100 = 554602 or c0000100 = 742201
     or c0000100 = 750601 or c0000100 = 783504 or c0000100 = 823503 or c0000100 = 1195501
     or c0000100 = 1195502 or c0000100 = 46701 or c0000100 = 42505 or c0000100 = 138901
     or c0000100 = 140105 or c0000100 = 140107 or c0000100 = 175404 or c0000100 = 265504
     or c0000100 = 506404 or c0000100 = 600702 or c0000100 = 780602 or c0000100 = 989201)
     then marbirth = 1;

if (c0000100 = 616902 or c0000100 = 616904 or c0000100 = 457801
   or c0000100 = 137801 or c0000100 = 249901 or c0000100 = 249902 or c0000100 = 83602
   or c0000100 = 231502 or c0000100 = 766202 or c0000100 = 800104 or c0000100 = 817405
   or c0000100 = 817406 or c0000100 = 265201) then marbirth = 0;


**get interview month and year;
intm79 = r0172500;
inty79 = 1979;
intm80 = r0329200;
inty80 = 1980;
intm81 = r0530700;
inty81 = 1981;
intm82 = r0809900;
inty82 = 1982;
intm83 = r1045700;
inty83 = 1983;
intm84 = r1427500;
inty84 = 1984;
intm85 = r1794600;
inty85 = 1985;
intm86 = r2156200;
inty86 = 1986;
intm87 = r2365700;
inty87 = 1987;
intm88 = r2742500;
inty88 = 1988;
intm89 = r2986100;
inty89 = 1989;
intm90 = r3302500;
inty90 = 1990;
intm91 = r3573400;
inty91 = 1991;
intm92 = r3917600;
inty92 = 1992;
intm93 = r4100200;
inty93 = 1993;
intm94 = r4500201;
inty94 = r4500202;
intm96 = r5200201;
inty96 = r5200202;
intm98 = r6435301;
inty98 = r6435302;
intm00 = r6963301;
inty00 = r6963302;
intm02 = r7656301;
inty02 = r7656302;
intm04 = r8423201;
inty04 = r8423202;
intm06 = t0967301;
inty06 = t0967302;
intm08 = t2190501;
inty08 = t2190502;

array mstat (23) r0217501 r0405601 r0618601 r0898401 r1144901 r1520101 r1890801
                 r2257901 r2445301 r2871000 r3074700 r3401400 r3656800 r4007300
                 r4418400 r5081400 r5166700 r6479300 r7007000 r7704300 r8496700
                 t0988500 t2210500;

array imon (23) intm79 intm80 intm81 intm82 intm83 intm84 intm85 intm86 intm87 intm88
                intm89 intm90 intm91 intm92 intm93 intm94 intm96 intm98 intm00 intm02
				intm04 intm06 intm08;

array iyr (23) inty79 inty80 inty81 inty82 inty83 inty84 inty85 inty86 inty87 inty88
                inty89 inty90 inty91 inty92 inty93 inty94 inty96 inty98 inty00 inty02
				inty04 inty06 inty08;

array imonx (23) imon79 imon80 imon81 imon82 imon83 imon84 imon85 imon86 imon87 imon88
                 imon89 imon90 imon91 imon92 imon93 imon94 imon96 imon98 imon00 imon02
				 imon04 imon06 imon08;

array mstatx (23) mstat79 mstat80 mstat81 mstat82 mstat83 mstat84 mstat85 mstat86 mstat87
                  mstat88 mstat89 mstat90 mstat91 mstat92 mstat93 mstat94 mstat96 mstat98
				  mstat00 mstat02 mstat04 mstat06 mstat08;

do k = 1 to 23;
   if imon(k) gt 0 and iyr(k) gt 0 then imonx(k) = (iyr(k)-1950)*12 + imon(k);
   mstatx(k) = mstat(k);
end;


**now, fill in some easy zeros, never married at an interview date after birth;
do k = 1 to 23;
if (marbirth = . and imonx(k) gt 0 and bd le imonx(k) and mstat(k) = 0) then marbirth = 0; 
end;

**no second marriage, marital start date comes before birth,
    so if married at interview after birth, then married at birth
    if divorced at interview before birth, then divorced at birth
    same logic for widowed;
   do k = 1 to 23;
if (marbirth = . and mars1 gt 0 and bd ge mars1 and secsmo = -997) then do;
   if (imonx(k) gt 0 and imonx(k) ge bd and mstat(k) = 1) then marbirth = 1;
   else if (imonx(k) gt 0 and imonx(k) le bd and mstat(k) = 3) then marbirth = 0;
   else if (imonx(k) gt 0 and imonx(k) le bd and mstat(k) = 6) then marbirth = 0;
   **separation is treated like still married in marriage ending cvs;
   else if (imonx(k) gt 0 and imonx(k) ge bd and mstat(k) = 2) then marbirth = 1;
end;
end;
if (c0000100 = 404503) then marbirth = 1;

**now, missing date of first marriage, but first marriage doesn't end;
do k = 1 to 23;
if (marbirth = . and mars1 = . and firpmo = -998) then do;
   if (imonx(k) gt 0 and imonx(k) le bd and mstat(k) = 1) then marbirth = 1;
   else if (imonx(k) gt 0 and imonx(k) le bd and mstat(k) = 2) then marbirth = 1;

end;
end;

**now missing date of stop of first marriage, but have date of marriage starts both first;
**and second, and born between date of first marriage and date of second marriage start;
do k = 1 to 23;
if (marbirth = . and mars1 ne . and marp1 = . and mars2 ne . and bd lt mars2 and bd ge mars1) 
    then do;
   if ((imonx(k) ge mars1) and (imonx(k) lt mars2) and (imonx(k) ge bd) and (mstat(k) = 1))
      then marbirth = 1;
	else if ((imonx(k) ge mars1) and (imonx(k) lt mars2) and (imonx(k) ge bd) and (mstat(k) = 2))
      then marbirth = 1;
	else if ((imonx(k) ge mars1) and (imonx(k) lt mars2) and (imonx(k) le bd) and (mstat(k) = 3))
      then marbirth = 0;
end;
end;


**for hand coding, will only use those bfeeding info. and test scores;
*if bfeed ne .;
*if (math56 ne .);
**couldn't code 5 in subsample;

keep c0000100 r0000100 bd marbirth;

*note, if child year of birth missing, had deleted obs.;

proc means;
run;

